package com.liuyucheng.idea_springboot.util;

import java.util.concurrent.CountDownLatch;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;

public class WriteTask implements Runnable {
    private CountDownLatch countDownLatch;
    private Sheet sheet;
    private String[] title;
    private CellStyle style;
    private int b;
    private String[][] values;

    public WriteTask(CountDownLatch countDownLatch, Sheet sheet, String[] title, CellStyle style, int b, String[][] values) {
        this.countDownLatch = countDownLatch;
        this.sheet = sheet;
        this.title = title;
        this.style = style;
        this.b = b;
        this.values = values;
    }

    public void run() {
        try {
            Row row = this.sheet.createRow(0);
            Cell cell = null;

            int i;
            for(i = 0; i < this.title.length; ++i) {
                cell = row.createCell(i);
                cell.setCellStyle(this.style);
                cell.setCellValue(this.title[i]);
            }

            for(i = 0; i < this.b; ++i) {
                row = this.sheet.createRow(i + 1);

                for(int j = 0; j < this.values[i].length; ++j) {
                    cell = row.createCell(j);
                    cell.setCellStyle(this.style);
                    cell.setCellValue(this.values[i][j]);
                }
            }
        } catch (Exception var8) {
        } finally {
            if (this.countDownLatch != null) {
                this.countDownLatch.countDown();
            }

        }

    }
}
